#include <stdio.h>

int halfSerch(int* arr, int low, int high, int key);

int main(int argc, char** argv) {
	int arr[5] = {1, 2, 3};
	int result;

	result = halfSerch(arr, 0, 2, 3);
	if (result == -1) {
		printf("No Result!");
	}
	else {
		printf("Result index is: %d", result);
	}

	return 0;
}
// 已经很好的说明了为什么mid要+1-1变low和high
int halfSerch(int* arr, int low, int high, int key) {
	int mid;
	while (low <= high) {
		mid = (low + high) / 2;
		if (arr[mid] == key) return mid;
		else if (arr[mid] < key) low = mid + 1;
		else high = low - 1;
	}
	return -1;
}
